package cn.ictgu.dao.service;

import cn.ictgu.dao.mapper.VideoMapper;
import cn.ictgu.dao.model.Video;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Video 服务
 * Created by Silence on 2016/11/28.
 */
@Service
public class VideoService {
  private final static int MOVIE_SIZE = 12;
  private final static int TV_SIZE = 12;
  private final static int ANIME_SIZE = 12;


  private final static String HOME_PIC = "HOME_PIC";
  private final static String HOME_RECOMMEND = "HOME_RECOMMEND";
  private final static String HOME_TV_HOT = "TV_HOME_HOT";
  private final static String HOME_MOVIE = "MOVIE_HOME";
  private final static String HOME_TV_MAIN = "TV_HOME_MAIN";
  private final static String HOME_TV_TOPS = "TV_HOME_TOPS";
  private final static String HOME_ANIME_HOT = "ANIME_HOME_HOT";
  private final static String HOME_ANIME_MAIN = "ANIME_HOME_MAIN";
  private final static String MOVIE = "MOVIE";
  private final static String TV = "TV";
  private final static String ANIME = "ANIME";

  @Autowired
  private VideoMapper mapper;

  public List<Video> select(String type, int index, int size){
    return mapper.selectByType(type, index, size);
  }

  public List<Video> selectHomePic(int size){
    return mapper.selectByType(HOME_PIC, 0, size);
  }

  public List<Video> selectHomeRecommend(int size){
    return mapper.selectByType(HOME_RECOMMEND, 0, size);
  }

  public List<Video> selectHomeTvHot(int size){
    return mapper.selectByType(HOME_TV_HOT, 0, size);
  }

  public List<Video> selectHomeMovie(int size){
    return mapper.selectByType(HOME_MOVIE, 0, size);
  }

  public Video selectHomeTvMain(){
    return mapper.selctOneByType(HOME_TV_MAIN);
  }

  public List<Video> selectHomeAnimeHot(int size){
    return mapper.selectByType(HOME_ANIME_HOT, 0, size);
  }

  public List<Video> selectHomeTvTop(int size) {
    return mapper.selectByType(HOME_TV_TOPS, 0, size);
  }

  public List<Video> selectHomeAnimeNew(int size) {
    return mapper.selectByType(ANIME, 0 , size);
  }

  public Video selectHomeAnimeMain(){
    return mapper.selctOneByType(HOME_ANIME_MAIN);
  }

  public List<Video> initMovies(){
    return mapper.selectLikeType(MOVIE, 0, MOVIE_SIZE * 2);
  }

  public List<Video> initTvs(){
    return mapper.selectLikeType(TV, 0, TV_SIZE * 2);
  }

  public List<Video> initAnimes(){
    return mapper.selectLikeType(ANIME, 0, ANIME_SIZE * 2);
  }

  public List<Video> selectMoviesByPage(int p){
    return mapper.selectLikeType(MOVIE, p * MOVIE_SIZE, MOVIE_SIZE);
  }

  public List<Video> selectTvsByPage(int p){
    return mapper.selectLikeType(TV, p * TV_SIZE, TV_SIZE);
  }

  public List<Video> selectAnimesByPage(int p){
    return mapper.selectLikeType(ANIME, p * ANIME_SIZE, ANIME_SIZE);
  }

  public Video selectById(long id){
    return mapper.selectById(id);
  }
}
